<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			let arr = [1, 3, 6, 2, 8, 3, 10];
			let temp = 0;
			function bubbleSort(arr) {
				let len = arr.length;
				for (let i = 0; i < len - 1; i++) {
					for (let j = 0; j < len - 1 - i; j++) {
						if (arr[j] > arr[j + 1]) { // 相邻元素两两对比
							temp = arr[j + 1]; // 元素交换
							arr[j + 1] = arr[j];
							arr[j] = temp;
						}
					}
				}
				return arr;
			}
			console.log(bubbleSort(arr));
		</script>
	</body>
</html>
